package com.x.uikit.service;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class XService {
    private static Map<Class<? extends XServiceModule>, XServiceModule> sServices = new ConcurrentHashMap<>();

    public static <T extends XServiceModule> T get(Class<T> clazz) {
        XServiceModule service = sServices.get(clazz);
        if (clazz.isInstance(service)) {
            return clazz.cast(service);
        }
        return null;
    }

    public static <T extends XServiceModule> void register(Class<T> clazz, T t) {
        if (clazz != null) {
            sServices.put(clazz, t);
        }
    }
}
